package com.wrial.kind.design;
/*
 * @Author  Wrial
 * @Date Created in 11:24 2020/8/18
 * @Description 使用两个栈实现一个队列
 */

import java.util.Stack;

public class Queue<E> {

    private Stack<E> stack1 = new Stack<>();
    private Stack<E> stack2 = new Stack<>();

    public void add(E e) {
        stack1.push(e);
    }

    public E remove() {
        if (stack2.size() != 0) {
            return stack2.pop();
        }
        int size = stack1.size();
        if (size == 0) return null;
        for (int i = 0; i < size; i++) {
            stack2.push(stack1.pop());
        }
        return stack2.pop();
    }

    public static void main(String[] args) {
        Queue<Integer> queue = new Queue<>();
        queue.add(1);
        queue.add(2);
        System.out.println(queue.remove());
        System.out.println(queue.remove());
        System.out.println(queue.remove());
    }
}
